package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.HealthEntity;
import com.ruoyi.web.dorm.entity.StudentHealthEntity;
import com.ruoyi.web.dorm.service.StuHealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/stuHealth")
public class StuHealthController extends BaseController {
    @Autowired
    private StuHealthService stuHealthService;

    /**
     * 查询学生卫生信息
     * @param studentHealthEntity
     * @return
     */
    @GetMapping("/getStuHealth")
    public TableDataInfo getStuHealth(StudentHealthEntity studentHealthEntity){
        startPage();
        return getDataTable(stuHealthService.getStuHealth(studentHealthEntity));
    }

    /**
     * 添加学生卫生信息
     * @param studentHealthEntity
     * @return
     */
    @PostMapping("/addStuHealth")
    public AjaxResult addStuHealth(@RequestBody StudentHealthEntity studentHealthEntity ){
        return toAjax(stuHealthService.addStuHealth(studentHealthEntity));
    }

    /**
     * 更新宿舍卫生信息
     * @param studentHealthEntity
     * @return
     */
    @PostMapping("/updateStuHealth")
    public AjaxResult updateStuHealth(@RequestBody StudentHealthEntity studentHealthEntity){
        return toAjax(stuHealthService.updateStuHealth(studentHealthEntity));
    }

    /**
     * 假删除学生卫生信息
     * @param id
     * @return
     */
    @DeleteMapping("/delStuHealth")
    public AjaxResult delStuHealth(Long id){
        return toAjax(stuHealthService.delStuHealth(id));
    }



    /**
     * 查询宿舍卫生信息导出信息
     * @param studentHealthEntity
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, StudentHealthEntity studentHealthEntity){
        List<StudentHealthEntity> list = stuHealthService.getStuHealth(studentHealthEntity);
        ExcelUtil<StudentHealthEntity> util = new ExcelUtil<>(StudentHealthEntity.class);
        util.exportExcel(response,list,"学生卫生信息数据");
    }
}
